#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>


//----------------------------------------------------------------------------//

WORD GetWindowRows( HWND hWnd, HDC hDC )
{
   TEXTMETRIC tm;
   RECT rct;
   WORD wRows;
   BOOL bDCDestroy = FALSE;

   if( ! hDC )
   {
      bDCDestroy = TRUE;
      hDC = GetDC( hWnd );
   }

   GetTextMetrics( hDC, &tm );
   GetClientRect( hWnd, &rct );
   wRows = ( rct.bottom - rct.top ) / tm.tmHeight;

   if( bDCDestroy )
      ReleaseDC( hWnd, hDC );

   return wRows;
}

//----------------------------------------------------------------------------//

CLIPPER nWRows()        // hWnd, hDC
{
   _retni( GetWindowRows( _parni( 1 ), _parni( 2 ) ) );
}

WORD GetWindowRow( HWND hWnd, HDC hDC, WORD wGraphRow ) // -> wTextRow
{
   TEXTMETRIC tm;
   RECT rct;
   WORD wRow;
   BOOL bDCDestroy = FALSE;

   if( ! hDC )
   {
      bDCDestroy = TRUE;
      hDC = GetDC( hWnd );
   }

   GetTextMetrics( hDC, &tm );
   GetClientRect( hWnd, &rct );
   wRow = ( wGraphRow - rct.top ) / tm.tmHeight;

   if( bDCDestroy )
      ReleaseDC( hWnd, hDC );

   return wRow;
}

//----------------------------------------------------------------------------//

CLIPPER nWRow()        // hWnd, hDC, nGraphRow -> nTextRow
{
   _retni( GetWindowRow( _parni( 1 ), _parni( 2 ), _parni( 3 ) ) );
}

//----------------------------------------------------------------------------//
